package com.xy.manage.service.impl;


import java.util.List;
import java.util.Map;
import java.util.Date;
import com.xy.core.util.BeanUtil;
import com.xy.common.page.Pagination;
import com.xy.common.util.Configure;
import com.xy.core.service.impl.BaseServiceImpl;

import org.apache.tomcat.dbcp.pool.impl.GenericKeyedObjectPool.Config;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.xy.manage.dao.TflashDao;
import com.xy.manage.model.Tflash;
import com.xy.manage.service.TflashService;

@Service
@Transactional
public class TflashServiceImpl extends BaseServiceImpl<Tflash> implements
		TflashService {
	private TflashDao tflashDao;

	public TflashServiceImpl(TflashDao paramAppRoleDao) {
		super(paramAppRoleDao);
		this.tflashDao = paramAppRoleDao;
	}

	@Override
	public boolean checkExist(String paraName, String paraValue) {
		return tflashDao.checkExist("Tflash", paraName, paraValue);
	}

	@Override
	public List<Tflash> getTflash(Map<String, Object> map) {
		return tflashDao.getTflash(map);
	}
	@Override
	public Pagination getTflashByPage(Map<String, Object> map, int pageNo,
			int pageSize) {
		// TODO Auto-generated method stub
		return tflashDao.getTflashByPage(map, pageNo, pageSize);
	}
	 
   @Override
	public Tflash save(Tflash tflash) {
	//	tflash.setModtime(new Date());
		if(tflash.getFid()==null){
			//新增
			tflash.setArea("0");
        	return super.save(tflash);
		}else{
			//更新
			Tflash tflash1=tflashDao.get(tflash.getFid());
			try {
				BeanUtil.copyNotNullProperties(tflash1, tflash);
			} catch (Exception e) {
				e.printStackTrace();
			}  
			return super.save(tflash1);
		}
	}

	@Override
	public boolean updatePath() {
		try {
			String outerpath = Configure.getProperty("outerpath");
			String innerpath = Configure.getProperty("innerpath");
			List<Tflash> list = tflashDao.getAll();
			for (Tflash t : list) {
				t.setInnerpath(innerpath.replace("*", t.getPiccode()));
				t.setPicpath(outerpath.replace("*", t.getPiccode()));
				tflashDao.save(t);
			}
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println();
			return false;
		}
	}

	@Override
	public Pagination getEntityByFuzzLoca(String keyword, int pageNo, int pageSize) {
		return tflashDao.getEntityByFuzzLoca(keyword, pageNo, pageSize);
	}
}